//
//  ViewController.m
//  UI_23_QQ_音乐界面
//
//  Created by li cheng on 16/8/15.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "MVTableViewCell.h"
#import "AFNetworking.h"
#define kTableViewCellReuse @"reuse"
#import "MVModel.h"
#import "MVData.h"
#import "MVShowPlay.h"
#import "MVContents.h"
#import "MVTableList.h"
#import "MVConllectionList.h"
#import "MVSingers.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *qqMVTableView;
@property (nonatomic, strong) MVModel *MVModel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _qqMVTableView.backgroundColor = [UIColor redColor];
    [self handleData];
}
- (void)handleData{
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    session.responseSerializer = [AFHTTPResponseSerializer serializer];
    [session GET:@"http://i.y.qq.com/v8/fcg-bin/getmv_by_tag?cmd=mv_shows_new&format=jsonp&g_tk=5381&uin=0&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=h5&needNewCode=1&_=1470996835294&jsonpCallback=jsonp1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSData *data = responseObject;
        NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________%@", dataString);
        dataString = [dataString stringByReplacingOccurrencesOfString:@"jsonp1(" withString:@""];
        dataString = [dataString substringToIndex:dataString.length - 1];
        NSLog(@"________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________%@", dataString);
        NSData *finalData = [dataString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error = nil;
        id reult = [NSJSONSerialization JSONObjectWithData:finalData options:NSJSONReadingMutableContainers error:&error];
        NSLog(@"_00000000000000_______________________________000000000000000_________________________________________________________________________________0000000000000____________________00000000000000000_____________________________________________________________________________________________________________________00000000000000_______________________________________________________________________________________________________0000000000000000________________________0000000000000000___________________________________________________________000000000000____________________________%@", reult);
        _MVModel = [MVModel modelWithDictionary:reult];
        [self.qqMVTableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"精选";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.MVModel.data.contents.list.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MVTableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    cell.array = _MVModel.data.contents.list[indexPath.section].mvlist;
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
